package main

import (
	"os"
	"os/signal"
	"server/src/logging"
	"server/src/storage"
	"syscall"
	"time"
)

const VER string = "处理数据服务器 v1.0 build 20240306"

func main() {
	// 根目录
	storage.Init(storage.RootPath())

	// 启动日志
	logging.DisableBootScreenLog()
	logging.LogBoot()

	zLog(VER, " 启动")
	// 加载配置
	cfg, err := loadConfig("")
	if err != nil {
		zLogError("启动 loadConfig error::", err.Error())
		return
	}

	// 连接数据库
	dbo, err := NewDBOperation(cfg)
	if err != nil {
		zLogError("数据库连接失败，程序退出:", err)
		return
	}
	zLog("数据库连接成功")
	defer dbo.Close()

	// 启动进程
	processor := NewProcessor(dbo, cfg)
	for i := 0; i < cfg.ProcessorNum; i++ {
		go processor.Run()
		time.Sleep(2 * time.Second)
	}

	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
	s := <-signalChan
	zLog("服务器收到退出信号:", s)
}
